<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@page import="com.framework.entity.Global"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html>
<html class="no-js">
<head>
<meta charset="UTF-8">
<title>确认订单</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="format-detection" content="telephone=no">
<meta name="renderer" content="webkit">
<meta http-equiv="Cache-Control" content="no-siteapp" />
<jsp:include page="/jsp/inc_head.jsp"></jsp:include>
<style>
#zhezhao{
    background:#333;
    bottom: 0;
	width:100%;
    display: none;
    left: 0;
    opacity: 0.9;
    position: fixed;
    right: 0;
    top: 0;
    z-index: 1000;
	}
.zzcltext{
    position: fixed;
    z-index: 1001;
    background: #fff;
    top: 30%;
    left: 50%;
    margin-left: -100px;
    width: 200px;
    height: 40px;
    text-align: center;
    border-radius: 10px;
    line-height: 40px;
}
.am-padding-0{
	padding:0;
}
	.orderinfo-orange{
		padding-top: 10px;
		padding-bottom: 10px;
		background: #fff;
		border-bottom:7px solid #eee;
	}
.beizhuarea{
		width:100%;
		padding:5px 10px;
		color:#aaa;
		font-size:13px;
		resize:none;
		border-style:solid;
		border-color:#eee;
		border-width:0 0 1px 0;	
		outline:none;
	}
.am-offcanvas-bar {	
	width: 100%;
	background: #fff;
}
.am-offcanvas-content {
	padding:0;
}
.am-offcanvas-bar:after {
	width: 0;
}

.shdz_lie{
	padding:12px 10px;
	border-bottom:1px solid #eeeeee;
	box-shadow:0 5px 5px #f9f9f9;
	color:#000;
	font-size:14px;	
}
.mrdz_span{
	padding:2px 10px;
	background-color:#ff6060;
	color:#fff;
	border-radius:20px;	
	font-size:12px;
}
.shdz_addr{
	line-height:18px;	
}
.btm_create{
	background-color:#ffbe23;
	color:#fff;		
}
.addbgcol{
	background-color:#ffdfdf;	
}

.botBtn {
    background-color: #ff4c00;
    border: none;
    color: #fff;
    font-size: 16px;
    line-height: 45px;
}
    .odqrsh{
		padding:12px 10px;
		background-color:#f6f6f6;	
		color:#000;
		font-size:13px;
	}
	.odshdown{
		color:#000;	
	}
	.orderinfo-orange{
		padding-top: 10px;
		padding-bottom: 10px;
		background: #fff;
		border-bottom:7px solid #eee;
	}	
	.jlqspanorange{
		background-color:#ff9f09;
		color:#fff;
		border-radius:4px;
		display:inline-block;
		padding:0 3px;
		font-size:12px;	
	}
	.beizhuarea{
		width:100%;
		padding:5px 10px;
		color:#aaa;
		font-size:13px;
		resize:none;
		border-style:solid;
		border-color:#eee;
		border-width:0 0 1px 0;	
		outline:none;
	}
	.btmodqr{
		position:fixed;
		bottom:45px;
		width:100%;
		background:#fafafa;
		padding:10px;
		color:#aaa;
		font-size:13px;
	}
	.payxjxj{
		display:inline-block;
		margin-left:5px;	
	}
	.fwfspan {
	    color: #acacac;
	    font-size: 12px;
	}
</style>
</head>
<body>
	<input type="hidden" id="orderid"/>
	<section class="am-g">
		<input type="hidden" id="addressId"/>
		<!--收货地址Id-->
		<!--     <input type="hidden" id="GivePhone">收货手机号id -->
		<input type="hidden" id="GiveCountyId"/>
		<!--收货地址区id-->
		<a href="#doc-oc-demo1" data-am-offcanvas  class="am-u-sm-12 ddqrDlxdDiv" style="display:none" id="shdzNo"> <!--没有收货地址时显示此链接-->
			<div class="am-u-sm-12 am-padding-0">
				<div class="am-u-sm-11 am-padding-0">请设置收货地址</div>
				
            <div class="am-u-sm-1 am-padding-0 am-text-right">
        		<i class="am-header-icon am-icon-angle-right am-icon-sm"></i>
            </div>
        
			</div> </a>
			
			 <a href="#doc-oc-demo1" data-am-offcanvas class="am-u-sm-12 ddqrYszxx" id="shdz"  <!--有收货地址时显示此链接--> </a>
		<div class="am-u-sm-12 am-padding-0 orderinfo-orange" id="goodsList"></div>
<!-- 		<div class="am-u-sm-12 qrddJsSpxx"> -->
<!-- 			共<span id="goodsCount">0</span>件商品 &nbsp; 运费:￥<span id="freight">0.00</span> -->
<!-- 		</div> -->
		<input type="hidden" id="freight"/>
		<input type="hidden" id="isMessage"/>
		<div class="am-u-sm-12 am-pad-none am-margin-top-sm">
	    	<div class="am-u-sm-12">
	        	备注
	        </div>
	        <div class="am-u-sm-12 am-pad-none">
	        	<textarea id="GiveMsg" class="beizhuarea" placeholder="输入填写留言内容"></textarea>
	        </div>
	    </div>
	</section>

	<!--footer-->
<!-- 	<div class="am-g gdDbdiv"></div> -->
<!-- 	<div class="footeNavbar qrddDbzfDiv"> -->
<!-- 		<div class="am-u-sm-12 am-padding-0 qrddDbzf"> -->
<!-- 			<div class="am-u-sm-7 am-padding-0"> -->
<!-- 				合计：<span class="colred">￥<span id="moneyTotle">0.00</span> </span> -->
<!-- 			</div> -->
<!-- 			<a class="am-u-sm-5 am-padding-0 spxqljgmBtn" onclick="submit();">微信支付</a> -->
<!-- 		</div> -->
<!-- 	</div> -->
	<!--footer-->
	<div class="am-modal am-modal-alert" tabindex="-1" id="my-alert">
		<div class="am-modal-dialog">
			<div class="am-modal-hd" id="alert_title">提示</div>
			<div class="am-modal-bd" id="alert_message"></div>
			<div class="am-modal-footer">
				<span class="am-modal-btn">确定</span>
			</div>
		</div>
	</div>
	
	<div class="btmodqr clear">
		<span class="">共1件商品</span>

	    <span class="am-fr payxjxj">
			<span class="">合计：
				<span class="jlqspanorange">久零券</span>
				<span class=""><span id="totalCoupons">0</span>券</span>
			</span>
	    	<%--需付现金：<span class="colred11">￥<span id="moneyTotle">0.00</span></span>--%>
	    </span>
	</div>
	<div class="am-g gdDbdiv"></div>
	<a class="am-u-sm-12 am-pad-none botBtn sqtkCxsq" href="javascript:;" style="width:100%;font-size:12px">
		<div class="am-u-sm-9 am-padding-0" style="border-right:1px solid #fff;">
			<span style="display: inline-block">久零币支付：<span class="colred11">￥<span id="coinPayTotal">0.00</span></span></span> &nbsp;
			<span style="display: inline-block">需付现金：<span class="colred11">￥<span id="moneyTotle">0.00</span></span></span>
		</div>
		<div class="am-u-sm-3 am-padding-0 am-text-center" onclick="submit();">立即支付</div>
	</a>

<!-- 侧边栏内容 -->
<div id="doc-oc-demo1" class="am-offcanvas">
    <div class="am-offcanvas-bar">
        <div class="am-offcanvas-content">
           <div class="am-g" id="shdzlb">
             
            </div>
            
            <div class="am-g btm_fixedsecond">
                <div class="am-u-sm-12 am-pad-none am-text-center">
                    <div class="am-u-sm-6 am-pad-none am-text-center btm_create" onClick="toNewAddr();">
                        管理收货地址
                    </div>
                    <div class="am-us-m-6 am-pad-none am-text-center btm_save" onClick="closeleftshow();">
                        确定
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<div id="zhezhao">
	<div class="zzcltext">
    	正在处理，请稍等。。。。
    </div>
</div>

    <div class="am-modal am-modal-alert" tabindex="-1" id="myAlert">
        <div class="am-modal-dialog">
            <div class="am-modal-hd">提示</div>
            <div class="am-modal-bd" id="myMsg">
                确定要去支付吗？
            </div>
            <div class="am-modal-footer">
                <span class="am-modal-btn" style="color:#999;" onclick="toOrder(1)">取消</span>
                <span class="am-modal-btn" style="color:#ff4c00" onclick="toOrder(2)">确定</span>
            </div>
        </div>
    </div>
<script type="text/javascript" src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
	<script>
var userId;
var type;
var freight=0;
var cartid;
var goodsId="";
var countyId="0";
var goodsValue=0;
var goodsCount=0;
var isUserIntegral=0;
var allCoupons = 0.00;
var allPayTotal = 0.00;
var coinOwnTotal = toDecimal2('${coinOwnTotal}');//久零币拥有额
var coinPayTotal = 0.00;//久零币支付额
var goodList;
var addId='';
var adds=[];
var isTicket=0;
var ajaxpath="${pageContext.request.contextPath}";
$(function(){

 userId='${userId}';
 type='${type}';
 cartid='${cartid}';
 loadGoods();
 loadAddress();
var json='${json}';
if(json!=null&&json!=undefined&&json!='')
{
	loadJSON(json);
}
});


//关闭侧边栏
function closeleftshow(){
	$("#doc-oc-demo1").offCanvas('close');	
}
//选择地址
function doSelect1(obj,id){
	addId=id;
	$(".shdz_lie").removeClass("addbgcol");		
	$("#div_"+id).addClass("addbgcol");
	for(var i=0;i<adds.length;i++)
	{
		if(adds[i].id==id)
		{
			loadDefault(adds[i]);
			break;
		}	
			
	}
}
function jisuan()
{
	$("#totalCoupons").html(toDecimal2(allCoupons));
	$("#coinPayTotal").html(toDecimal2(coinPayTotal));
	//支付总额 = 总额+运费-久零币支付额
	$("#moneyTotle").html(accSub(accAdd(parseFloat(allPayTotal),
			parseFloat($("#freight").val())), parseFloat(coinPayTotal)));
}

function  loadfreight()
{
 	var url=ajaxpath+'/order/loadFreight.do?goodsId='+goodsId;
 	$.get(url, function(result){ 	
		var data=JSON.parse(result);
		var list=data.list;
		if(data.isOverlay==1)//叠加
		{
			if(data.freighType==1)//统一运费
			{
				freight=toDecimal2(accMul(parseFloat(data.freightmoney),parseFloat(goodsCount)));
			}else
			{
				$(list).each(function(i){//模板
					var yunfei=list[i].freightMoney;
					if(countyId==list[i].freeCountyId)
					{
						yunfei=0;
					}
					var count=$("#count_"+list[i].id).html();
					freight=toDecimal2(accAdd(accMul(parseFloat(count),parseFloat(yunfei)),parseFloat(freight)));
				});
			}
		}else{//不叠加
			if(data.freighType==1)//统一运费只算一次
			{
				freight=data.freightmoney;
			}else{
//				alert(list.length);
				if(list != undefined)
				{
					freight=getMin(list);
				}
			}//模板算最小值
		}
		$("#freight").val(freight);
		jisuan();
	});
}

function getMin(list)
{
var min=list[0].freightMoney;
$(list).each(function(i){
var yunfei=list[i].freightMoney;
if(countyId==list[i].freeCountyId)
{yunfei=0;}
if(parseFloat(min)>parseFloat(yunfei))
{min=yunfei;}
});
return toDecimal2(min);
}
// function  loadIntegralRule()
// {
//  var url=ajaxpath+'/integral/loadIntegralRule.do';
//  	$.get(url, function(result){ 	
//  	var rule=eval(JSON.parse(result));
// 	var integral=$("#userIntegral").html();
// 	var cutMoney= toDecimal2(accMul(parseFloat(integral),parseFloat(rule))) ;
// 	if(parseFloat(cutMoney)>parseFloat(goodsValue))
// 		{$("#integralCut").html(goodsValue);}
// 		else
// 		{$("#integralCut").html(cutMoney);}
// 	});
// }

function  loadGoods()
{
	 var url=ajaxpath+'/cart/loadCartGoods.do?type='+type+'&cartId='+cartid+'';
 	$.get(url, function(result){
 //	alert(result);
 	var data=eval(result);
 	var html=''; 	
 	goodList=data;
 		$(data).each(function(i){
 		html+=' <div class="am-u-sm-12 qrddWwdiv"> <div class="am-u-sm-3 am-padding-0">';
			if(data[i].mainType == '3')
			{
				html+=' <img src="<%=Global.OSSURL_MAINTYPE3%>/';
			}else{
				html+=' <img src="<%=Global.OSSURL%>/';
			}
			html+= data[i].goodsPic
															+ '" class="sptpimg" /> </div>'
															+ '<div class="am-u-sm-9 am-padding-0">'
															+ ' <div class="am-u-sm-12 am-padding-0 infoname">'
															+ data[i].goodsName 
															+ '</div>'
															+ '<div class="am-u-sm-12 infogg">'
															+ data[i].type1
															+ '：'
															+ data[i].typeValue1;
															if(data[i].type2 != '')
															{
																html+= ' &nbsp;' 
																	+data[i].type2
																	+ '：'
																	+data[i].typeValue2;
															}
															if(data[i].type3 != '')
															{
																html+= ' &nbsp;' 
																	+data[i].type3
																	+ '：'
																	+data[i].typeValue3;
															}
															html+='</div>'
															+ '<div class="am-u-sm-12 am-padding-0" style="font-size:13px;">'
															+ ' <div class="am-fl am-padding-0 colred">';
															var  fwf=(data[i].goodsPirce*0.03).toFixed(2);

															if(data[i].isTicket == '0'){
                                                                isTicket=0;
																html+='<span class="jlqspanorange">久零券</span>';
																html+='<span class="colred11">'+data[i].goodsPirce+'券</span>';
																html+='<span class="fwfspan" id="fwf">(含服务费'+fwf+'元)</span>';
															}else{
                                                            isTicket=1
																html+='<span class="">￥'+data[i].goodsPirce+'元</span>';
															}
															html+='</div>'
															+ ' <div class="am-fr am-padding-0 am-text-right">X<span id="count_'+data[i].id+'">'
															+ data[i].count
															+ '</span></div>'
															+ '  </div>  </div>  </div>';
													if(data[i].isTicket == '0')
													{		
														allPayTotal = toDecimal2(accAdd(
															parseFloat(allPayTotal),
															parseFloat(fwf*data[i].count)));

														if(accSub(coinOwnTotal,allPayTotal) >=0)
														{
															coinPayTotal = allPayTotal;
														}else{
															coinPayTotal = coinOwnTotal;
														}
														allCoupons = toDecimal2(accAdd(
															parseFloat(allCoupons),
															parseFloat(accMul(
																	parseFloat(data[i].goodsPirce),
																	parseFloat(data[i].count)))));
													}else{
														allPayTotal = toDecimal2(accAdd(
															parseFloat(allPayTotal),
															parseFloat(accMul(
																	parseFloat(data[i].goodsPirce),
																	parseFloat(data[i].count)))));
														if(accSub(coinOwnTotal,allPayTotal) >=0)
														{
															coinPayTotal = allPayTotal;
														}else{
															coinPayTotal = coinOwnTotal;
														}
													}

													goodsId += data[i].id + ",";
												});
								$("#goodsList").html(html);
								loadfreight();
// 								jisuan();
							});
		}


        var isorder=false;//是否已经生成订单:true:已经生产，false:未生成
		function submit() {
			if(isorder){
			//如果订单已经生产，则跳转我的订单页面支付
			window.location.href = ajaxpath+"/jsp/order/orderList.jsp?guid="+ new Date();
			}
			$("#zhezhao").css("display","block");//遮罩层
		
			var addressId = $("#addressId").val();
			var GiveType = $("#GiveType").val();
			var GiveMsg = $("#GiveMsg").val();
			var GivePhone = $("#GivePhone").val();
			var isMessage = $("#isMessage").val();
			if (addressId == '' || addressId == null || addressId == undefined) {
				$("#zhezhao").css("display","none");//遮罩层
				$("#alert_message").html("请设置收货地址!");
				$("#my-alert").modal('open');
				return false;
			}
			var Message = $("#Message").val();
			if (isMessage == "0") {
				Message = "";
			}
			var DiscountState = isUserIntegral;
			var ShopId = 123;
			var PayTotal = $("#moneyTotle").html();
			var couponsTotal = $("#totalCoupons").html();
			var json = '{"AddressId":"' + addressId + '","GiveType":"'
					+ GiveType + '","GiveMsg":"' + GiveMsg + '",'
					+ '"GivePhone":"' + GivePhone + '","Message":"' + Message
					+ '","DiscountState":"' + DiscountState + '",'
					+ '"ShopId":"' + ShopId + '","PayTotal":"' + PayTotal
					+ '","couponsPayTotal":"' + couponsTotal
					+ '",';
			var json1 = '[';
			var json2 = '[]';
			$(goodList).each(function(i) {
				json1 += '{"CartId":"' + goodList[i].id + '"},';
			});
			json1 += ']';
			json += '"CardList":' + json2 + ',"GoodsList":' + json1 + '}';

			$.ajax({
				url : ajaxpath + "/order/produceOrder.do?json=" + json,
				type : 'post',
				async : false,
				success : function(data) {
					var result = data.result;
					if (result == 'success') {
						//成功
						$("#orderid").val(data.ordercode);
						//doPaywx(data.ordercode);//微信付款
						//payorder();//测试
						doXinYePay(data.ordercode);//兴业银行
					} else {
					    $("#zhezhao").css("display","none");//遮罩层
						var msg_return=data.msg;
						if(msg_return=="存在已删除购物车商品信息"){
						//订单已经生产，购物已经清空，跳转支付页面
						window.location.href = ajaxpath+"/jsp/order/orderList.jsp?guid="+ new Date(); 
						}else{
						$("#alert_message").html(msg_return);
						$("#my-alert").modal('open');
					    }
					}
				}
			});

		}

		//付款
		function payorder() {
			var codes = $("#orderid").val();
			var payCodes = '';
			$.ajax({
				url : ajaxpath + '/orderPay/toPayOrder.do',
				type : "post",
				data : {
					codes : codes,
					payCodes : payCodes
				},
				dataType : "json",
				success : function(data) {
					window.location.href = ajaxpath
							+ "/client_toClientCenter.do";
				}
			});
		}
		
		
		//兴业银行支付
		function doXinYePay(ordercodeArr){
		//var ordercodeArr = "464668823432432";//订单号 order_main_id
		$.ajax({
				url : ajaxpath + '/payBank/toPayBankOrder.do?isTicket='+isTicket,
				type : "post",
				data : {
					ordercodeArr : ordercodeArr,
					attach : 0
				},
				dataType : "json",
				success : function(data) {
					if(data.result){
						window.location.href ="https://pay.swiftpass.cn/pay/jspay?token_id="+data.msg+"&showwxtitle=1";
					}else{
                      //  alert(isTicket);
                        if(data.msg=='支付失败：扣除券点失败'&&isTicket==0){
                            var url=ajaxpath+"/userCenter/getUserCenterJNInfo.do";
                            var jlye='0';
                            var spye=$("#totalCoupons").html();
                            var html='';
							var chargeAmount = '';
							var giveAmount = '';
                            var hcye='';
                            $.get(url,function(data){
                                if(data.return_data!=undefined&&data.return_data!=null)
                                {
                                    jlye=(data.return_data.balance_90/100).toFixed(2);
                                }
                                 hcye=(spye-jlye).toFixed(2);
                                 html='您的久零券余额为'+jlye+'，还差'+hcye+'，是否先去联盟专区获得久零券？';
                                $("#myMsg").html(html);
                                $("#myAlert").modal('open');
                            });
                        }else{
                            alert(data.msg);
                            window.location.href = ajaxpath
                            + "/client_toClientCenter.do";
                        }

					}
					
				}
			});
			
		}
		
    function toOrder(i){
        if(i==1){
            window.location.href = ajaxpath
            + "/client_toClientCenter.do";
        }else{
            window.location.href=ajaxpath+"/client_toGoodsList.do?isTicket=1";
        }
    }


		//微信支付
		function doPaywx(ordercodeArr){
		//var ordercodeArr = "464668823432432";//订单号   
		var moneyArr = 0.01;//支付金额
	    var url = ajaxpath+"/orderPay/doRecharge.do?money="+moneyArr+"&ordercodeArr="+ordercodeArr+"&guid="+new Date().getTime();
		
			$.get(url,function(data){
				var jsParam= data.jsParam;
				$("#zhezhao").css("display","none");//遮罩层
				//alert(jsParam);
				jsParam = eval('(' + jsParam + ')');
				WeixinJSBridge.invoke(
						'getBrandWCPayRequest'
						,jsParam
						,function(res){
							//  返回 res.err_msg,取值 
							// get_brand_wcpay_request:cancel   用户取消 
							// get_brand_wcpay_request:fail  发送失败 
							// get_brand_wcpay_request:ok 发送成功 
								WeixinJSBridge.log(res.err_msg);
								if (res.err_msg == 'get_brand_wcpay_request:ok')
								{
								//支付成功
								window.location.href=ajaxpath+"/client_toClientCenter.do";
								}else{
								//支付失败
								alert("支付失败");
								}
						}
					);
			}
			);
		}

		function loadAddress() {

			var url = ajaxpath + '/order/loadAddress.do';
			$.get(url,function(result) {
								var list = JSON.parse(result);
								var html='';
								if(list.length<=0)
									{
									

									$("#addressId").val('');
									$("#shdzNo").show();
									$("#shdz").hide();
									}
								else
									{
									
									for(var i=0;i<list.length;i++)
									{
										var obj={};
										var data=list[i];
										obj.id=data.id;
										obj.name=data.name;
										obj.phone=data.phone;
										obj.pr=  data.pr;
										obj.ct= data.ct;
										obj.ar=data.ar;
										obj.addDetail=data.addDetail;
										
										adds.push(obj);
									if(data.isdefault==1)
									{loadDefault(data);}
									
									html+='<div class="am-u-sm-12 shdz_lie" id="div_'+data.id+'" onclick="doSelect1(this,\''+data.id+'\')">'+
									' <div class="am-u-sm-11 am-pad-none">'+
									'<div class="am-u-sm-12 am-pad-none">'+
									  ' <div class="am-u-sm-3 am-pad-none">'+
									  data.name+
									  '</div>'+
					                   '<div class="am-u-sm-9 am-pad-none">'+
									   data.phone+
									   '</div></div>'+
									   '<div class="am-u-sm-12 am-pad-none">'+
									   ' <div class="am-u-sm-3 am-pad-none">';
									   if(data.isdefault==1)
									   {html+='<span class="mrdz_span">默认</span>';}
					                      html+='</div>'  +
										  '  <div class="am-u-sm-9 am-pad-none shdz_addr">'+
										  ' </div>'+
										   data.pr+
											 data.ct+
											 data.ar+
											 data.addDetail +
											'</div> </div>'+												
										   //' <div class="am-u-sm-1 am-padding-0 am-text-right">'+
											//	'<i class="am-header-icon am-icon-angle-right am-icon-sm"></i>'+
										// '   </div>'+
										 ' </div>';
					               
									}
									$("#shdzlb").html(html);
									}
															

							});
		}
			function loadDefault(data)
			{
					var html = '<div class="am-u-sm-12 am-padding-0">'
							+ '<div class="am-u-sm-7 am-padding-0">'
							+ '收货人 &nbsp;'
							+ data.name
							+ '</div>'
							+ '<div class="am-u-sm-5 am-padding-0 am-text-right">'
							+ data.phone
							+ '</div>'
							+ '</div>'
							+ '<div class="am-u-sm-12 am-padding-0">'
							+ '<div class="am-u-sm-11 am-padding-0">地址：'
							+ data.pr
							+ data.ct
							+ data.ar
							+ data.addDetail + '</div>' +
								'<div class="am-u-sm-1 am-padding-0 am-text-right">'+
								'<i class="am-header-icon am-icon-angle-right am-icon-sm"></i>'+
								'</div>'+
							'</div>';
					$("#shdz").html(html);
					$("#shdz").show();
					$("#shdzNo").hide();
					$("#addressId").val(data.id);
				
			
			}
		function accAdd(arg1, arg2) { //浮点数运算加法
			var r1, r2, m;
			try {
				r1 = arg1.toString().split(".")[1].length;
			} catch (e) {
				r1 = 0;
			}
			try {
				r2 = arg2.toString().split(".")[1].length;
			} catch (e) {
				r2 = 0;
			}
// 			alert(r2);
			m = Math.pow(10, Math.max(r1, r2));
			return (arg1 * m + arg2 * m) / m;
		}
		//浮点数运算减法
		function accSub(arg1, arg2) {
			return accAdd(arg1, -arg2);
		}
		//浮点数运算乘法
		function accMul(arg1, arg2) {
			var m = 0, s1 = arg1.toString(), s2 = arg2.toString();
			try {
				m += s1.split(".")[1].length;
			} catch (e) {
			}
			try {
				m += s2.split(".")[1].length;
			} catch (e) {
			}
			return Number(s1.replace(".", "")) * Number(s2.replace(".", ""))
					/ Math.pow(10, m);
		}
		//浮点数运算除法
		function accDiv(arg1, arg2) {

			var t1 = 0, t2 = 0, r1, r2;
			try {
				t1 = arg1.toString().split(".")[1].length;
			} catch (e) {
			}
			try {
				t2 = arg2.toString().split(".")[1].length;
			} catch (e) {
			}

			with (Math) {
				r1 = Number(arg1.toString().replace(".", ""));
				r2 = Number(arg2.toString().replace(".", ""));

				return (r1 / r2) * pow(10, t2 - t1);
			}
		}
		function toDecimal2(x) {
			var f = parseFloat(x);
			if (isNaN(f)) {
				return 0.00;
			}
			var f = Math.round(x * 100) / 100;
			var s = f.toString();
			var rs = s.indexOf('.');
			if (rs < 0) {
				rs = s.length;
				s += '.';
			}
			while (s.length <= rs + 2) {
				s += '0';
			}
			return s;
		}
		
		
		function toNewAddr()
		{
			var addressId = $("#addressId").val();
			var GiveType = $("#GiveType").val();
			var GiveMsg = $("#GiveMsg").val();
			var GivePhone = $("#GivePhone").val();
			var isMessage = $("#isMessage").val();		
			var Message = $("#Message").val();			
			var DiscountState = isUserIntegral;
			var ShopId = 123;
			var PayTotal = $("#moneyTotle").html();
			var json = '{"AddressId":"' + addressId + '","GiveType":"'
					+ GiveType + '","GiveMsg":"' + GiveMsg + '",'
					+ '"GivePhone":"' + GivePhone + '","Message":"' + Message+ '","isMessage":"' + isMessage
					+ '","DiscountState":"' + DiscountState + '",'
					+ '"ShopId":"' + ShopId + '","PayTotal":"' + PayTotal
					+ '","Type":"' + type+ '","Cart":"' + cartid
					+ '",';
			var json1 = '[';
			var json2 = '[]';
			$(goodList).each(function(i) {
				json1 += '{"CartId":"' + goodList[i].id + '"},';
			});
			json1=json1.substring(0, json1.length-1);
			json1 += ']';
			json += '"CardList":' + json2 + ',"GoodsList":' + json1 + '}';
			window.location.href = ajaxpath
			+ "/client_toAddress2.do?json="+json;
		}
		
		function loadJSON(json)
		{
			var data=JSON.parse(json);
			
			  $("#addressId").val(data.AddressId);
			
			 $("#GiveMsg").val(data.GiveMsg);
			 $("#GivePhone").val(data.GivePhone);
			 //$("#isMessage").val(data.);	
			 var message=data.Message;
			 var discountState=data.DiscountState;
			 var isMessage=data.isMessage;
			 if(isMessage==1)
			 {
				 $("#isMessage").val('1');
				 $("#Message").val(data.Message);
				// $("#lycheckbox").prop("checked");
				 $("#lycheckbox").prop('checked',true);
				 $("#hidehkly").slideDown();
				 //$("#lycheckbox").parent().parent().next().stop().slideDown();
			 }
			 else
			{
				 $("#isMessage").val('0');
				  $("#Message").val(data.Message);
				 $("#lycheckbox").prop('checked',false);
				 $("#hidehkly").slideUp();
			}
			 
			 if(discountState==1)
			{
				 isUserIntegral=1;
				 $("#jfcheckbox").prop('checked',true);
				 $("#hidejfdk").slideDown();
			}
			 else
			{
				 isUserIntegral=0;
				 $("#jfcheckbox").prop('checked',false);
				 $("#hidejfdk").slideUp();
				 //$("#jfcheckbox").parent().parent().next().stop().slideUp();
			}
			//isUserIntegral;
			
			
			//$(this).parent().parent().next().stop().slideDown();1
		
			//$(this).parent().parent().next().stop().slideUp();
			 var giveType=data.GiveType;
			 if(giveType == 0){
					$("#GiveType").val(0);
						$("#zsradioshowT").stop().hide();
						$("#zsradioshowO").stop().fadeIn();
						$("#zsradio").prop('checked',true);
					}else{
						$("#GiveType").val(1);
						$("#zsradioshowO").stop().hide();
						$("#zsradioshowT").stop().fadeIn();
						$("#zsradio1").prop('checked',true);
					}
			
			
			$("#moneyTotle").html(data.PayTotal);
			$("#doc-oc-demo1").offCanvas('open');
		}
	</script>
</body>
</html>


